package FlowGram.Application.IDEWindow.FileHost;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;

import FlowGram.Application.Parser.FinchProgramFlow;

public class FlowEditor extends Editor {
	private JScrollPane flowEditorScrollPane;

	public FlowEditor(){
		JEditorPane flowEditorPane = new JEditorPane();
		flowEditorPane.setEditable(false);

		//Put the editor pane in a scroll pane.
		flowEditorScrollPane = new JScrollPane(flowEditorPane);
		flowEditorScrollPane .setVerticalScrollBarPolicy(
		                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		flowEditorScrollPane .setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		flowEditorScrollPane .setPreferredSize(new Dimension(400, 700));
		flowEditorScrollPane .setMinimumSize(new Dimension(200, 300));
		flowEditorScrollPane .setBorder(BorderFactory.createLineBorder (Color.blue, 2));
		this.add(flowEditorScrollPane );
	}
	
	public int getCaretPosition(){
		return this.getFlowEditorPane().getCaretPosition();
	}
	
	public void setUpFlowEditor(FinchProgramFlow programFlow){
		String codeString = programFlow./*toHTML("action")*/toCode();
		this.getFlowEditorPane().setText(codeString);
	}
	
	public JEditorPane getFlowEditorPane(){
		JViewport viewport = flowEditorScrollPane.getViewport(); 
		JEditorPane codeEditorPane = (JEditorPane)viewport.getView();
		return codeEditorPane;
		
		
	}
}
